var oper = getQueryString('oper')
var grayId = getQueryString('id')
$(function () {

    $('#oper').val(oper)
    if (oper === 'edit' || oper === 'view') {
        grayDetail(grayId)
    }

    $.common.initFormInfo();



    jQuery.validator.addMethod("portFormat", function (value, element) {
        return !(value < 0 || value > 65535)
    },"端口范围0~65535");

    jQuery.validator.addMethod("nameFormat", function (value, element) {
        var reg = /^[^\u4e00-\u9fa5]+$/;
        return reg.test(value)
    },"不能包含中文");
});


$("#editForm").validate({
    onkeyup: false,
    rules: {
        serverIp: {
            required: true,
            isIp: true
        },
        serverPort: {
            required: true,
            portFormat: true
        },
        springApplicationName: {
            required: true,
            nameFormat: true
        },
    },
    messages: {
        serverIp: {
            required: "请输入IP地址"
        },
        serverPort: {
            required: "请输入端口号"
        },
        springApplicationName: {
            required: "请输入服务名"
        },
    },
    focusCleanup: true
});



function grayDetail(id) {
    $.operate.get(api + '/admin/sysgrayitem/' + id, function (res) {
        res.data.oper = oper
        applyDrawing('#editForm', res.data)

        $.common.initFormInfo();
    }, false)
}


function submitHandler() {
    if ($.validate.form()) {
        $.common.ajaxCommitForm($('#editForm'), false);
        return false;
    }
}